home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / progbar.exe / TPROGBAR.H < prev   
C/C++ Source or Header  |  1992-10-12  |  4KB  |  94 lines

  1. // #if defined( Uses_TProgressBar ) && !defined( __TProgressBar )
  2. // #define __TProgressBar
  3.  
  4. /* Include the commented directives above if you want to implement this
  5.    in your TV.LIB. Don't forget the #endif at the end of this file! To
  6.    utilize "#define Uses_TProgressBar" put the follow directives in TV.H, 
  7.    after #if defined( Uses_TButton ) would be a good place.
  8.  
  9. #if defined( Uses_TProgressBar )
  10. #define Uses_TView
  11. #define __INC_DIALOGS_H
  12. #endif
  13.  
  14.    After uncommenting the top two directives of this header file and the 
  15.    #endif at the end of this header file copy the contents of this file to 
  16.    the DIALOGS.H file in TVISION\INCLUDE. Put it before the last set of 
  17.    directives or to be safe somewhere in the middle between "#define Uses_*" 
  18.    blocks. Don't forget to make a backup of DIALOGS.H if you make mistakes.
  19.  
  20.    In MAKEFILE. in \TVISION\SOURCE edit the OBJS = statement to include
  21.    TPROGBAR.OBJ or compile it alone and just add it to the TV.LIB via
  22.    TLIB (easier).
  23.  
  24.    To comiple individually and use try:
  25.      bcc -c -P -O1 -ml -I<include dirs> -n<obj dirs> tprogbar.cpp
  26.         + add "-Y -Vs -B" for overlay version of TV.
  27.      tlib tv.lib /0 +TPROGBAR
  28.  
  29.    For example:
  30.          bcc -c -P -O1 -kl -I\BC\INCLUDE;\BC\TVISION\INCLUDE tprogbar.cpp
  31.          tlib \BC\TVISION\LIB\TV.LIB /0 +tprogbar
  32.  
  33.    After this you can remove TPROGBAR.CPP from your project list and it will
  34. be included in the link with TV.LIB.
  35.  
  36. */
  37.  
  38. class far TRect;
  39.  
  40. class TProgressBar : public TView
  41. {
  42. public:
  43.    // default the background char to 178, but you can pass any char you want
  44.    TProgressBar(TRect& r, unsigned long iters, char abackChar='▓');
  45.    ~TProgressBar();
  46.    virtual void draw();
  47.    virtual TPalette& getPalette() const;
  48.    virtual void update(unsigned long aProgress);
  49.  
  50.    inline unsigned long getTotal();    // get the maximum iteration
  51.    inline unsigned long getProgress();    // get the current iteration
  52.  
  53.    // change the percentage ( calls the update function )
  54.    void setTotal(unsigned long newTotal); // set the maximum iteration
  55.    void setProgress(unsigned long newProgress); // set the current iteration
  56.  
  57. protected:
  58.    char          backChar;   // background character
  59.    unsigned long total;      // total iterations to complete 100 %
  60.    unsigned long progress;   // current iteration value
  61.    char *        bar;         // thermometer bar
  62.    unsigned int  dispLen;    // length of bar
  63.    unsigned int  curPercent; // current percentage
  64.    unsigned int  curWidth;
  65.    unsigned int  numOffset;  // offset in the string to display the percentage
  66.    double        charValue;
  67.  
  68. private:
  69.    virtual const char* streamableName() const
  70.       {return name;}
  71.    void calcPercent();     // calculate new percentage
  72.  
  73. protected:
  74.    TProgressBar( StreamableInit) : TView( streamableInit ) {};
  75.    virtual void write(opstream&);
  76.    virtual void *read(ipstream&);
  77.  
  78. public:
  79.    static const char * const near name;
  80.    static TStreamable *build();
  81. };
  82.  
  83. inline ipstream& operator >> ( ipstream& is, TProgressBar& cl )
  84.     { return is >> (TStreamable&)cl; }
  85. inline ipstream& operator >> ( ipstream& is, TProgressBar*& cl )
  86.     { return is >> (void *&)cl; }
  87.  
  88. inline opstream& operator << ( opstream& os, TProgressBar& cl )
  89.     { return os << (TStreamable&)cl; }
  90. inline opstream& operator << ( opstream& os, TProgressBar* cl )
  91.     { return os << (TStreamable *)cl; }
  92.  
  93. //#endif      // defined( Uses_TProgressBar ) && !defined( __TProgressBar )
  94.